/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} sum
 * @return {boolean}
 */
var arr = [];
var hasPathSum = function (root, sum) {
  arr.push(root.val);
  if (!root) return false;
  if (!root.left && !root.right) {
    if (root.val === sum) {
      console.log(arr)
      return true
    }
    arr.pop();
    return false
  }
  if (root.left) {
    var a = hasPathSum(root.left, sum - root.val)
  }
  if (root.right) {
    var b = hasPathSum(root.right, sum - root.val)
  }

  return Boolean(a || b)
};